package com.rcadmin.core.web;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rcadmin.common.exception.BusiException;

//@ControllerAdvice(annotations=RestController.class)
//@ControllerAdvice(basePackages={"com.xxx","com.ooo"})
@ControllerAdvice
public class GlobalExceptionHandler {
	protected static Logger logger = LoggerFactory
			.getLogger(GlobalExceptionHandler.class);

	@ExceptionHandler(RuntimeException.class)
	// @ExceptionHandler(value={RuntimeException.class,MyRuntimeException.class})
	// @ExceptionHandler//处理所有异常
	@ResponseBody
	// 在返回自定义相应类的情况下必须有，这是@ControllerAdvice注解的规定
	public BusiException exceptionHandler(RuntimeException e,
			HttpServletResponse response) {
		logger.error(e.getMessage(), e);
		return null;
	}
}